#include "link_list.h"
#include "../test.h"

void test()
{
	void *ep;
	link_list mylist;
	struct mydata elem = {4,'d'},ee = {14,'e'}, e0,
			e1 = {1,'a'},e2 = {2,'b'},
			e3 = {3,'c'}, e4 = {4,'d'};

	linklist_init(&mylist);

	linklist_insert(mylist, 1, (void *) &e1, sizeof(struct mydata));
	linklist_insert(mylist, 2, (void *) &e2, sizeof(struct mydata));
	linklist_insert(mylist, 3, (void *) &e3, sizeof(struct mydata));
	linklist_insert(mylist, 4, (void *) &e4, sizeof(struct mydata));
	
	linklist_delete(mylist,2,(void *) &e0, sizeof(struct mydata));
	visit((void *)&e0);
	//linklist_clear(mylist);
	//linklist_destroy(&mylist);
	linklist_traverse(mylist, visit);
	printf("%d\n",linklist_empty(mylist));
	printf("%d\n",linklist_length(mylist));

	//visit(linklist_getelem(mylist, 0));//it just exit

	printf("%d,,,...,.\n",linklist_locateelem(mylist,(void *)&elem, my_compare,sizeof(struct mydata)));
}

void test2(){
	link_list la,lb,lc;
	struct mydata elem;
	int i;
	linklist_init(&la);
	linklist_init(&lb);
	srand(343);
	for(i = 0; i < 11; i++){
		//elem.value = rand()%10;
		elem.value = i*2;
		elem.ch = 'a';
		linklist_insert(la,i+1,(void *)&elem, sizeof(struct mydata));
		//elem.value = rand()%10;
		elem.value = i*2+10;
		elem.ch = 'b';
		linklist_insert(lb,i+1,(void *)&elem, sizeof(struct mydata));
	}
//	linklist_traverse(la,visit);
//	linklist_traverse(lb,visit);
	linklist_merge(&la,&lb,&lc,my_compare);
	linklist_traverse(lc,visit);
	
}

int main(){

	test2();
}

